package org.mrjbee.share.it.easy.client;

import java.io.IOException;

import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

public class App 
{
    public static void main(String[] args) throws Exception{
    	if (args.length < 2){
    		System.out.println("Args should be: port,command");
    		System.exit(1);
    	}
    	JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:"+args[0]+"/jmxrmi");
    	JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    	MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
    	
    	
    	ObjectName mbeanName = new ObjectName("org.mrjbee.shared.clipboard.client.daemon:type=RemoteControl");
    	Object result = mbsc.invoke(mbeanName,"exec",new String[]{args[1]},new String[]{String.class.getName()});
    	System.out.println("Executed with:"+result);
    }
}
